home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************************
- * *
- * EQUALIZER.CPP: The main program, the core of this application *
- * *
- * Copyright (C) 2000 Andrei Grecu *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
- * *
- * If you have questions, bug reports regarding my code please contact me at: *
- * andrei.grecu@aon.at *
- * *
- * Home page: *
- * http://members.aon.at/grxpage/index.htm *
- * *
- **********************************************************************************/
-
- #include "precomp.h"
- #include "resource.h"
- #include "misc.h"
- #include "fdt.h"
- LPVOID AllocMemory(DWORD dwsize);
- #define FreeMemory(ptr) GlobalFree((HGLOBAL)ptr)
-
- typedef struct tagRTEQTRACKBAR {
-
- HWND hWnd;
- /* HBITMAP Track, Bar;
- int TrackWidth, TrackHeight, BarWidth, BarHeight;*/
- int pos, maxpos, minpos;
- tagRTEQTRACKBAR *next;
-
- } RTEQTRACKBAR;
-
- typedef RTEQTRACKBAR * LPRTEQTRACKBAR;
-
- HBITMAP Track = 0, Bar;
- int TrackWidth, TrackHeight, BarWidth, BarHeight;
-
- extern HINSTANCE hInst; // current instance
-
- LPRTEQTRACKBAR lptrkbar = NULL;
-
- ATOM RTEQTrackBarRegisterClass(HINSTANCE hInstance);
- LRESULT CALLBACK TrackBarWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
-
- void DrawTrackBar(HWND hWnd, HDC hdc);
- LPRTEQTRACKBAR AppendTrackBar(HWND hWnd);
- void RemoveTrackBar(HWND hWnd);
- LPRTEQTRACKBAR GetTrackBar(HWND hWnd);
-
- //
- // FUNCTION: MyRegisterClass()
- //
- // PURPOSE: Registers the window class.
- //
- // COMMENTS:
- //
- // This function and its usage is only necessary if you want this code
- // to be compatible with Win32 systems prior to the 'RegisterClassEx'
- // function that was added to Windows 95. It is important to call this function
- // so that the application will get 'well formed' small icons associated
- // with it.
- //
- ATOM RTEQTrackBarRegisterClass(HINSTANCE hInstance)
- {
- WNDCLASSEX wcex;
-
- wcex.cbSize = sizeof(WNDCLASSEX);
-
- wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;// | CS_SAVEBITS;
- wcex.lpfnWndProc = (WNDPROC)TrackBarWndProc;
- wcex.cbClsExtra = 0;
- wcex.cbWndExtra = 0;
- wcex.hInstance = hInstance;
- wcex.hIcon = NULL;
- wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
- wcex.hbrBackground = CreateSolidBrush(RGB(192, 192, 192));
- wcex.lpszMenuName = NULL;
- wcex.lpszClassName = "RTEQTrackBar";
- wcex.hIconSm = NULL;
-
- return RegisterClassEx(&wcex);
- }
-
- //
- // FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
- //
- // PURPOSE: Processes messages for the main window.
- //
- // WM_COMMAND - process the application menu
- // WM_PAINT - Paint the main window
- // WM_DESTROY - post a quit message and return
- //
- //
- LRESULT CALLBACK TrackBarWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
-
- #define STR_LENGTH 4096
-
- switch (message)
- {
- case WM_CREATE:
- {
- if(!Track) {
- LPSTR path = (LPSTR) AllocMemory(STR_LENGTH);
- LPSTR name = (LPSTR) AllocMemory(STR_LENGTH);
- LPSTR file = (LPSTR) AllocMemory(STR_LENGTH);
-
- GetCurrentDirectory(STR_LENGTH, path);
- GetPrivateProfileString("Skin", "Name", "default", name, STR_LENGTH, "EQUALIZER.INI");
- lstrcat(path, "\\");
- lstrcat(path, name);
- lstrcat(path, "\\"); // Syntax "C:\\CurrentDirectory\\name\\"
- lstrcpy(name, path); // name = path
-
- GetPrivateProfileString("Skin", "Track", "track.bmp", file, STR_LENGTH, "EQUALIZER.INI");
- lstrcat(name, file);
-
- Track = (HBITMAP) LoadImage(NULL, name, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
- if(!Track) {
- Track = (HBITMAP) LoadImage(hInst, (LPSTR)IDB_TRACK, IMAGE_BITMAP, 0, 0, 0);
- }
-
- lstrcpy(name, path); // name = path
- GetPrivateProfileString("Skin", "Bar", "bar.bmp", file, STR_LENGTH, "EQUALIZER.INI");
- lstrcat(name, file);
-
- Bar = (HBITMAP) LoadImage(NULL, name, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
- if(!Bar) {
- Bar = (HBITMAP) LoadImage(hInst, (LPSTR)IDB_BAR, IMAGE_BITMAP, 0, 0, 0);
- }
-
- BITMAP bm;
- GetObject(Track, sizeof(BITMAP), &bm);
- TrackWidth = bm.bmWidth;
- TrackHeight = bm.bmHeight;
- GetObject(Bar, sizeof(BITMAP), &bm);
- BarWidth = bm.bmWidth;
- BarHeight = bm.bmHeight;
-
- FreeMemory(name);
- FreeMemory(path);
- FreeMemory(file);
- }
-
- LPRTEQTRACKBAR lpTrackBar = AppendTrackBar(hWnd);
-
- HDC hdc = GetDC(hWnd);
- DrawTrackBar(hWnd, hdc);
- ReleaseDC(hWnd, hdc);
-
- }
-
- break;
- case WM_SIZE:
- {
- HDC hdc = GetDC(hWnd);
- DrawTrackBar(hWnd, (HDC)wParam);
- ReleaseDC(hWnd, hdc);
- }
- break;
- case WM_ERASEBKGND:
- case WM_PAINT:
- //if(message == WM_PAINT) DefWindowProc(hWnd, message, wParam, lParam);
- if(wParam) {
- HDC hdc = GetDC(hWnd);
- DrawTrackBar(hWnd, hdc);
- ReleaseDC(hWnd, hdc);
- }
- else return(DefWindowProc(hWnd, message, wParam, lParam));
- break;
- case WM_DESTROY:
- {
- /* LPRTEQTRACKBAR lpTrackBar = GetTrackBar(hWnd);
- DeleteObject(lpTrackBar->Track);
- DeleteObject(lpTrackBar->Bar);*/
- RemoveTrackBar(hWnd);
- }
- break;
-
- case TBM_GETPOS:
- {
- LPRTEQTRACKBAR lpTrackBar = GetTrackBar(hWnd);
- return(-lpTrackBar->pos);
- }
- case TBM_SETPOS:
- {
- LPRTEQTRACKBAR lpTrackBar = GetTrackBar(hWnd);
- lpTrackBar->pos = -(LONG)(lParam);
- if(wParam) {
- HDC hdc = GetDC(hWnd);
- SendMessage(hWnd, WM_PAINT, (WPARAM)hdc, 0);
- ReleaseDC(hWnd, hdc);
- }
- }
- break;
- case TBM_SETRANGE:
- {
- LPRTEQTRACKBAR lpTrackBar = GetTrackBar(hWnd);
- lpTrackBar->minpos = HIWORD(lParam);
- lpTrackBar->maxpos = (signed short)LOWORD(lParam);
- if(wParam) {
- HDC hdc = GetDC(hWnd);
- SendMessage(hWnd, WM_PAINT, (WPARAM)hdc, 0);
- ReleaseDC(hWnd, hdc);
- }
- }
- break;
-
- //////////////////////////////////
- case WM_LBUTTONDOWN:
- SetCapture(hWnd);
- break;
- case WM_LBUTTONUP:
- if(GetCapture() == hWnd) ReleaseCapture();
- break;
- case WM_MOUSEMOVE:
- if(wParam && MK_LBUTTON == MK_LBUTTON) {
- int x = (short)LOWORD(lParam), y = (short)HIWORD(lParam);
-
- RECT rc;
- GetClientRect(hWnd, &rc);
-
- LPRTEQTRACKBAR lpTrackBar = GetTrackBar(hWnd);
- COEF rel_height = (COEF)rc.right * BarHeight / BarWidth;
- COEF bar_position = (COEF)y / (COEF)(rc.bottom - rel_height);
- bar_position = (COEF)lpTrackBar->minpos - bar_position * (2 * abs(lpTrackBar->maxpos));
- if(bar_position < lpTrackBar->minpos && bar_position > lpTrackBar->maxpos) {
- lpTrackBar->pos = (INT)bar_position;
- }
- else if(bar_position > lpTrackBar->minpos) {
- lpTrackBar->pos = lpTrackBar->minpos;
- }
- else if(bar_position < lpTrackBar->maxpos) {
- lpTrackBar->pos = lpTrackBar->maxpos;
- }
- HDC hdc = GetDC(hWnd);
- SendMessage(hWnd, WM_PAINT, (WPARAM)hdc, 0);
- ReleaseDC(hWnd, hdc);
- SendMessage(GetParent(hWnd), WM_VSCROLL, MAKELONG(0, -lpTrackBar->pos), (LPARAM) hWnd);
- }
- break;
-
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- return 0;
- }
-
- void DrawTrackBar(HWND hWnd, HDC hdc) {
-
- LPRTEQTRACKBAR lpTrackBar = GetTrackBar(hWnd);
-
- // ****** Draw Track ************************************************************
- RECT rc;
- GetClientRect(hWnd, &rc);
-
- HDC hcdc = CreateCompatibleDC(hdc);
-
- SetStretchBltMode(hdc, HALFTONE);
- SetStretchBltMode(hcdc, HALFTONE);
-
- HGDIOBJ saveObj = SelectObject(hcdc, Track);
- StretchBlt(hdc, 0, 0, rc.right, rc.bottom, hcdc, 0, 0, TrackWidth, TrackHeight, SRCCOPY);
- //BitBlt(lpTrackBar->hdc, 0, 0, rc.right, rc.bottom, lpTrackBar->hcdc, 0, 0, SRCCOPY);
- SelectObject(hcdc, saveObj);
-
- saveObj = SelectObject(hcdc, Bar);
-
- COEF rel_height = (COEF)rc.right * BarHeight / BarWidth;
- COEF log_position = (COEF)((COEF)lpTrackBar->minpos - lpTrackBar->pos) / ((COEF)2 * abs(lpTrackBar->maxpos));
- int abs_position = (INT)(log_position * (rc.bottom - rel_height));
- if(abs_position < 0) abs_position = 0;
-
- StretchBlt(hdc, 0, (INT)abs_position, rc.right, (INT)rel_height, hcdc, 0, 0, (INT)BarWidth, (INT)BarHeight, SRCCOPY);
- //BitBlt(lpTrackBar->hdc, 0, abs_position, rc.right, abs_position + rc.right, lpTrackBar->hcdc, 0, 0, SRCCOPY);
- SelectObject(hcdc, saveObj);
-
- DeleteDC(hcdc);
-
- // ****** Draw Bar ************************************************************
- }
-
- LPRTEQTRACKBAR AppendTrackBar(HWND hWnd) {
-
- if(!lptrkbar) {
- lptrkbar = (LPRTEQTRACKBAR) AllocMemory(sizeof(RTEQTRACKBAR));
- lptrkbar->hWnd = hWnd;
- lptrkbar->pos = 0;
- lptrkbar->next = NULL;
- return(lptrkbar);
- }
- else {
- LPRTEQTRACKBAR lpHLPtrkbar = lptrkbar;
- while(lpHLPtrkbar->next != NULL) lpHLPtrkbar = lpHLPtrkbar->next;
-
- LPRTEQTRACKBAR lpNEWtrkbar = (LPRTEQTRACKBAR) AllocMemory(sizeof(RTEQTRACKBAR));
- lpNEWtrkbar->hWnd = hWnd;
- lpNEWtrkbar->pos = 0;
- lpNEWtrkbar->maxpos = -100;
- lpNEWtrkbar->minpos = 100;
- lpNEWtrkbar->next = NULL;
-
- lpHLPtrkbar->next = lpNEWtrkbar;
- return(lpNEWtrkbar);
-
- }
-
- return(NULL);
-
- }
-
- void RemoveTrackBar(HWND hWnd) {
-
- if(lptrkbar != NULL && lptrkbar->next == NULL) {
- FreeMemory(lptrkbar);
- }
- else if(lptrkbar != NULL) {
- LPRTEQTRACKBAR lpHLPtrkbar = lptrkbar->next;
- LPRTEQTRACKBAR lpHLPtrkbar2 = lptrkbar;
- while(lpHLPtrkbar->next != NULL && lpHLPtrkbar->hWnd != hWnd) {
- lpHLPtrkbar = lpHLPtrkbar->next;
- lpHLPtrkbar2 = lpHLPtrkbar2->next;
- }
-
- if(lpHLPtrkbar->next == NULL && lpHLPtrkbar->hWnd != hWnd) return;
-
- lpHLPtrkbar2->next = lpHLPtrkbar->next;
- FreeMemory(lpHLPtrkbar);
- }
-
- }
-
- LPRTEQTRACKBAR GetTrackBar(HWND hWnd) {
-
- if(lptrkbar) {
- LPRTEQTRACKBAR lpHLPtrkbar = lptrkbar;
- while(lpHLPtrkbar->next != NULL && lpHLPtrkbar->hWnd != hWnd) lpHLPtrkbar = lpHLPtrkbar->next;
-
- if(lpHLPtrkbar->next == NULL && lpHLPtrkbar->hWnd != hWnd) return(NULL);
-
- return(lpHLPtrkbar);
-
- }
-
- return(NULL);
-
- }
-